package com.warm.spring.exception;

import lombok.Getter;
import org.springframework.util.ObjectUtils;

import java.util.HashMap;
import java.util.Map;

/**
 * @Date: 2020/3/31 17:11
 * @Author: LChuang
 * @Description: 继承自 RuntimeException 的抽象类，可以看做系统中其他异常类的父类
 */
@Getter
public abstract class BaseException extends RuntimeException {

    private final ErrorEnum error;

    private final HashMap<String, Object> data = new HashMap<>();

    public BaseException(ErrorEnum error, Map<String, Object> data) {
        super(error.getMessage());
        this.error = error;
        if (!ObjectUtils.isEmpty(data)) {
            this.data.putAll(data);
        }
    }

    protected BaseException(ErrorEnum error, Map<String, Object> data, Throwable cause) {
        super(error.getMessage(), cause);
        this.error = error;
        if (!ObjectUtils.isEmpty(data)) {
            this.data.putAll(data);
        }
    }
}
